"""
-*- coding: utf-8 -*-
@Time    : 2024-12-16 22:58
@Author  : TheWindbell07
@File    : 7.py
"""
import urllib.request as ur
import urllib.parse as up
from lxml import etree
import os
import pandas as pd


def openUrl(url):
    request = ur.Request(url)
    request.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0')
    response = ur.urlopen(request)
    html = response.read()
    return html

def getMeaning(word):
    parse_json_list = {}
    # print("\n正在爬取信息...")

    parse_json = {}
    url = 'https://hanyu.baidu.com/zici/s?from=aladdin&query=' + up.quote(word) + '&srcid=51368&wd=' + up.quote(word)
    html = openUrl(url).decode('utf-8', errors='ignore')
    html = etree.HTML(html)

    # 部首 = html.xpath("//li[@id='radical']//span//text()")
    笔划数 = html.xpath("//li[@id='stroke_count']//span//text()")
    # 拼音 = html.xpath("//div[@id='pinyin']//span//b//text()")
    # 相关组词 = html.xpath("//div[@class='content link-terms']//a//text()")
    # 相关组词 = ['_'.join([word[i:i+2] for i in range(0, len(word), 2)]) for word in 相关组词]
    # 基本释义 = ''.join([str(e) for e in html.xpath("//div[@id='basicmean-wrapper']//p/text()")]).replace(" ",
    #                                                                                                      "").replace(
    #     "\n", "")

    # parse_json["radical"] = 部首
    parse_json["stroke_count"] = 笔划数
    # parse_json["related_words"] = 相关组词
    # parse_json["pinyin"] = 拼音
    # parse_json["basic_meaning"] = 基本释义

    parse_json_list[url] = parse_json
    # save(parse_json_list, word)
    return 笔划数

def is_chinese(char):
    if '\u4e00' <= char <= '\u9fff':
        return True
    else:
        return False

if __name__ == '__main__':
    words = input("> ")
    print("运行中...")
    # for paragraph in doc.paragraphs:
    #     words.extend(list(paragraph.text))
    res = []
    for word in words:
        if not is_chinese(word):
            continue
        if int(getMeaning(word)[0]) == 7:
            res.append(word)

    print(res)
